unit contact;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  hadeobject;

type

  { TContact }

  TContact = class(THadeObject)
  private
    fAddress: string;
    fContactName: string;
    fEmail: string;
    fOIDPerson: integer;
    fPhone: string;
  published
    property ContactName: string read fContactName write fContactName;
    property oidPerson: integer read fOIDPerson write fOIDPerson;
    property Address: string read fAddress write fAddress;
    property Email: string read fEmail write fEmail;
    property Phone: string read fPhone write fPhone;
  end;

  { TContactList }

  TContactList = class(THadeObjectList)
  private
  protected
    function getItem(index: integer): TContact; reintroduce;
  public
    property Items[index: integer]: TContact read getItem;

    //procedure getAll();
    //procedure getFirst();
    //procedure getContactByOIDPerson(const oid: integer);
  end;

procedure RegisterMapping;

//var
//  lsession: THadeSession;

implementation

uses
  hademapping,
  hadecriteria;

procedure RegisterMapping;
begin
  GHadeMappingManager.RegisterMapping('test', TContact, 'contact', 'OID', 'oid',
    ftInteger, 0, [ptkPK, ptkReadOnly]);

  GHadeMappingManager.RegisterMapping('test', TContact, 'contact',
    'ContactName', 'contact_name',
    ftVarchar, 25);

  GHadeMappingManager.RegisterMapping('test', TContact, 'contact', 'Address', 'address',
    ftString, 0);

  GHadeMappingManager.RegisterMapping('test', TContact, 'contact', 'Email', 'email',
    ftVarchar, 50);

  GHadeMappingManager.RegisterMapping('test', TContact, 'contact', 'Phone', 'phone',
    ftVarchar, 16);

  GHadeMappingManager.RegisterMapping('test', TContact, 'contact',
    'oidPerson', 'oidPerson',
    ftReference, 0, [ptkFK]);

  GHadeMappingManager.RegisterObjectList('test', TContactList, TContact);

//  lsession := GHadeSessionFactory.CreateSession('test');
end;

{ TContactList }

function TContactList.getItem(index: integer): TContact;
begin
  Result := TContact(inherited getItem(index));
end;

//procedure TContactList.getAll;
//begin
//  lsession.Read(self);
//end;
//
//procedure TContactList.getFirst;
//begin
//  lsession.Read(self, 0, 1);
//end;

//procedure TContactList.getContactByOIDPerson(const oid: integer);
//var
//  lCriteria: THadeCriteria;
//begin
//  lCriteria := THadeCriteria.Create;
//  lCriteria.Equal('oidperson', oid);
//  lSession.Read(self, lCriteria);//<<inject criteria onto session.read
//end;

end.

